﻿Imports DevExpress.XtraSplashScreen

Public Class DMBenhNhan
    Public Overrides Sub setSubTruoc_Thoat()
        TiepNhanBenhNhan.setMaBenhNhan(Me.IGridView1.GetFocusedRowCellValue("ma"))
    End Sub
    Public Overrides Sub setSubTruoc_TaoMoi()
        Me.BarCheckItemNhapTuDanhSach.Checked = False
    End Sub
    Private Sub DMBenhNhan_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SplashScreenManager.ShowForm(GetType(WaitForm1))
        Me.DMDanTocTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.DMDanToc)
        Me.DMTinhTrangTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.DMTinhTrang)
        Me.DMTinhThanhTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.DMTinhThanh)
        Me.DMPhuongXaTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.DMPhuongXa)
        Me.DMQuocGiaTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.DMQuocGia)
        Me.DMQuanHuyenTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.DMQuanHuyen)
        Me.DMNganhNgheTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.DMNganhNghe)
        Me.BenhNhanTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.BenhNhan)
        Me.GioiTinhTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.GioiTinh)
        Me.DMBenhNhanTableAdapter.Fill(Me.PCV_CLINICDataSet_Don.DMBenhNhan)
        Me.IGridControl.ForceInitialize()
        Me.IGridView1.MoveLast()
        Me.setHeaderFooter("Công Ty CP Tư Vấn Giải Pháp ERP Phong Cách Việt", "Lâm Văn Bền, P.Tân Kiểng, Q.7, TP.HCM")
        SplashScreenManager.CloseForm()
    End Sub
    Public Sub New()
        InitializeComponent()
        Me.setObj(Me.PCV_CLINICDataSet_Don, Me.PCV_CLINICDataSet_Don.DMBenhNhan, Me.DMBenhNhanBindingSource, Me.TableAdapterManager, DMBenhNhanTableAdapter, Me.MaITextEdit)
        Me.IGridView1.setBatLoi("ma", "not null")
    End Sub
    Private Shadows Sub BarButtonItemBaoCao_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemBaoCao.ItemClick
        Dim report As XtraReportDMBenhNhan = New XtraReportDMBenhNhan
        report.ShowRibbonPreview()
    End Sub
    'Lọc Tỉnh thành theo quốc gia
    Private Sub TinhthanhISearchLookupEdit_Enter(sender As Object, e As System.EventArgs) Handles TinhthanhISearchLookupEdit.Enter
        Me.DMTinhThanhBindingSource.Filter = "maquocgia='" & Me.QuocgiaISearchLookupEdit.EditValue.ToString & "'"
    End Sub
    'Lọc Quận huyện theo tỉnh thành
    Private Sub QuanhuyenISearchLookupEdit_Enter(sender As Object, e As System.EventArgs) Handles QuanhuyenISearchLookupEdit.Enter
        Me.DMQuanHuyenBindingSource.Filter = "matinhthanh='" & Me.TinhthanhISearchLookupEdit.EditValue.ToString & "'"
    End Sub
    'Lọc Phường xã theo quận huyện
    Private Sub PhuongxaISearchLookupEdit_Enter(sender As Object, e As System.EventArgs) Handles PhuongxaISearchLookupEdit.Enter
        Me.DMPhuongXaBindingSource.Filter = "maquanhuyen='" & Me.QuanhuyenISearchLookupEdit.EditValue.ToString & "'"
    End Sub
    'Hiện group BHYT khi loại bệnh nhân là BHYT
    Private Sub LoaibenhnhanISearchLookupEdit_EditValueChanged(sender As Object, e As System.EventArgs) Handles LoaibenhnhanISearchLookupEdit.EditValueChanged
        If state <> 0 And Not IsDBNull(Me.LoaibenhnhanISearchLookupEdit.EditValue) And Not IsNothing(Me.LoaibenhnhanISearchLookupEdit.EditValue) Then
            If Me.LoaibenhnhanISearchLookupEdit.EditValue.ToString = "BHYT" Then
                Me.LayoutControlGroupBHYT.Enabled = True
                Me.SobhytITextEdit.Properties.ReadOnly = False
                Me.NgaybatdauIDateEdit.Properties.ReadOnly = False
                Me.NgayhethanIDateEdit.Properties.ReadOnly = False
                Me.TraituyenICheckEdit.Properties.ReadOnly = False
            Else
                Me.LayoutControlGroupBHYT.Enabled = False
                Me.SobhytITextEdit.Properties.ReadOnly = True
                Me.NgaybatdauIDateEdit.Properties.ReadOnly = True
                Me.NgayhethanIDateEdit.Properties.ReadOnly = True
                Me.TraituyenICheckEdit.Properties.ReadOnly = True
            End If
        End If
    End Sub
    'Lấy Tỉnh thành, quận huyện, phường xã... sang DiaChiITextEDit
    Private Sub DiachiITextEdit_GotFocus(sender As Object, e As System.EventArgs) Handles DiachiITextEdit.GotFocus
        If state <> 0 And Not (IsDBNull(Me.PhuongxaISearchLookupEdit.EditValue) AndAlso IsDBNull(Me.QuanhuyenISearchLookupEdit.EditValue) AndAlso IsDBNull(Me.TinhthanhISearchLookupEdit.EditValue) AndAlso IsDBNull(Me.ThonphoduongITextEdit.EditValue) AndAlso IsDBNull(Me.SonhaITextEdit.EditValue)) Then
            Me.DiachiITextEdit.EditValue = " " & Me.SonhaITextEdit.EditValue & ", " & Me.ThonphoduongITextEdit.EditValue & ", " & Trim(Me.PhuongxaISearchLookupEdit.Properties.GetDisplayValueByKeyValue(Me.PhuongxaISearchLookupEdit.EditValue)) & ", " & Trim(Me.QuanhuyenISearchLookupEdit.Properties.GetDisplayValueByKeyValue(Me.QuanhuyenISearchLookupEdit.EditValue)) & ", " & Trim(Me.TinhthanhISearchLookupEdit.Properties.GetDisplayValueByKeyValue(Me.TinhthanhISearchLookupEdit.EditValue))
            Me.DiachiITextEdit.EditValue = LTrim(Me.DiachiITextEdit.EditValue.ToString.Replace(" ,", ""))
        End If
    End Sub
    Public Overrides Sub setSubSau_Sua()
        If Not IsDBNull(Me.LoaibenhnhanISearchLookupEdit.EditValue) And Not IsNothing(Me.LoaibenhnhanISearchLookupEdit.EditValue) Then
            If Me.LoaibenhnhanISearchLookupEdit.EditValue.ToString = "BHYT" Then
                Me.LayoutControlGroupBHYT.Enabled = True
                Me.SobhytITextEdit.Properties.ReadOnly = False
                Me.NgaybatdauIDateEdit.Properties.ReadOnly = False
                Me.NgayhethanIDateEdit.Properties.ReadOnly = False
                Me.TraituyenICheckEdit.Properties.ReadOnly = False
            Else
                Me.LayoutControlGroupBHYT.Enabled = False
                Me.SobhytITextEdit.Properties.ReadOnly = True
                Me.NgaybatdauIDateEdit.Properties.ReadOnly = True
                Me.NgayhethanIDateEdit.Properties.ReadOnly = True
                Me.TraituyenICheckEdit.Properties.ReadOnly = True
            End If
        End If

    End Sub
    Public Overrides Sub setSubSau_TaoMoi()
        Me.QuocgiaISearchLookupEdit.EditValue = "VN"
        Me.DantocISearchLookupEdit.EditValue = "kinh"
    End Sub
    'Tính năm sinh khi tuổi thay đổi
    Private Sub TuoiITextEdit_EditValueChanged(sender As Object, e As System.EventArgs) Handles TuoiITextEdit.EditValueChanged
        If Me.state <> 0 AndAlso Not IsDBNull(Me.TuoiITextEdit.EditValue) AndAlso Not IsNothing(Me.TuoiITextEdit.EditValue) AndAlso Me.TuoiITextEdit.IsNeedFocus Then
            Dim namhientai As Integer = CInt(Now.Year)
            Me.NamsinhITextEdit.EditValue = namhientai - CInt(TuoiITextEdit.EditValue)
        End If
    End Sub
    'Tính tuổi khi năm sinh thay đổi
    Private Sub NamsinhITextEdit_EditValueChanged(sender As Object, e As System.EventArgs) Handles NamsinhITextEdit.EditValueChanged
        If Me.state <> 0 AndAlso Not IsDBNull(Me.NamsinhITextEdit.EditValue) AndAlso Not IsNothing(Me.NamsinhITextEdit.EditValue) AndAlso Me.NamsinhITextEdit.IsNeedFocus AndAlso Not Me.NamsinhITextEdit.EditValue.ToString = "" AndAlso CInt(Me.NamsinhITextEdit.EditValue) <= CInt(Now.Year) Then
            Dim namhientai As Integer = CInt(Now.Year)
            Me.TuoiITextEdit.EditValue = namhientai - CInt(NamsinhITextEdit.EditValue)
        End If
    End Sub
    'Lấy năm sinh từ NgaythangnamsinhIDateEdit
    Private Sub NgaythangnamsinhIDateEdit_EditValueChanged(sender As Object, e As System.EventArgs) Handles NgaythangnamsinhIDateEdit.EditValueChanged
        If state <> 0 AndAlso Not IsDBNull(Me.NgaythangnamsinhIDateEdit.EditValue) AndAlso Not IsNothing(Me.NgaythangnamsinhIDateEdit.EditValue) AndAlso Me.NgaythangnamsinhIDateEdit.EditValue.ToString <> "" AndAlso Me.NgaythangnamsinhIDateEdit.IsNeedFocus Then
            Me.NamsinhITextEdit.EditValue = Format(CDate(Me.NgaythangnamsinhIDateEdit.EditValue), "yyyy")
        End If
    End Sub

    Private Sub TenITextEdit_EditValueChanged(sender As Object, e As System.EventArgs) Handles TenITextEdit.EditValueChanged
        If Me.state <> 0 AndAlso Not IsDBNull(Me.TenITextEdit.EditValue) AndAlso Not IsNothing(Me.TenITextEdit.EditValue) AndAlso Not Me.TenITextEdit.EditValue.ToString = "" Then
            Dim sten As String = Me.TenITextEdit.EditValue.ToString.ToUpper
            Me.TenITextEdit.EditValue = sten
        End If
    End Sub
End Class
